import torch
import torchvision
from torch import nn
from torch.nn import Conv2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
from urllib3.filepost import writer

datset = torchvision.datasets.CIFAR10("data",
                                      train=False,
                                      transform=torchvision.transforms.ToTensor(),
                                      download=True)

dataloader = DataLoader(datset, batch_size=64)


class Tudui(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(in_channels=3, out_channels=6,
                               kernel_size=3,
                               stride=1, padding=0)

    def forward(self, x):
        x = self.conv1(x)
        return x


tudui = Tudui()
# print(tudui)

writer = SummaryWriter("logs")
step = 0
for data in dataloader:
    if step == 1:
        break
    imgs, targets = data
    output = tudui(imgs)
    # print(imgs.shape)
    # print(output.shape)
    writer.add_images("input", imgs, step)  # torch.Size([64, 3, 32, 32])
    # 第一个值不知道写什么所以写的-1
    output = torch.reshape(output, (-1, 3, 30, 30))
    print(output.shape)  # 调整后变成了torch.Size([128, 3, 30, 30])
    writer.add_images("output", output, step)  # torch.Size([64, 6, 30, 30])
    step = step + 1

writer.close()